package db_utils

import "dgo/goutils/utils"

func MakeAddFieldSQL(tablename, fieldname, fieldtype, defaultval string, canbenull bool, afterfield string) string {
	var sb utils.BytesBuilder
	sb.Appendf("ALTER TABLE %s ADD COLUMN %s %s", tablename, fieldname, fieldtype)
	if canbenull {
		sb.AppendStr(" NULL ")
	}
	if len(defaultval) > 0 {
		sb.AppendStr(" DEFAULT ").AppendStr(defaultval)
	}
	if len(afterfield) > 0 {
		sb.Appendf(" AFTER %s", afterfield)
	}
	sb.AppendStr(";")
	return sb.String()
}
